package com.czy.owner.ui.workorder;
import android.widget.RatingBar;
import android.widget.TextView;
import com.czy.owner.R;
import com.czy.owner.db.UserHelper;
import com.czy.owner.entity.SeeEvaluateModel;
import com.czy.owner.global.Constants;
import com.czy.owner.ui.BaseActivity;
import com.czy.owner.utils.GsonUtils;
import com.czy.owner.utils.PhoneUtils;

import org.xutils.common.Callback;
import org.xutils.http.RequestParams;
import org.xutils.x;

import butterknife.BindView;

/**
 * Created by wangyang on 2016/9/18 0018.
 * 查看评价
 */
public class SeeEvaluateActivity2 extends BaseActivity {
    @BindView(R.id.ratingbar_big_encourage)
    RatingBar ratingbarBigEncourage;
    @BindView(R.id.ratingbar_intimate_index)
    RatingBar ratingbarIntimateIndex;
    @BindView(R.id.ratingbar_benefit_index)
    RatingBar ratingbarBenefitIndex;
    @BindView(R.id.ratingbar_efficiency_index)
    RatingBar ratingbarEfficiencyIndex;
    @BindView(R.id.tv_content)
     TextView tvContent;
    private String order_number;
    private int storeId;

    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_see_evaluate;
    }

    @Override
    protected void initInjector() {

    }

    @Override
    protected void initViews() {
        getToolbarTitle().setText(R.string.see_evaluate);
        order_number = getIntent().getStringExtra("orderNumber");
        seeEvaluateData();

    }

    @Override
    protected void updateViews() {

    }

    private void seeEvaluateData() {
        mLoadView.ShowLoadView();
        storeId = getIntent().getIntExtra("storeId", 0);
        String url = Constants.APP_API_BASE + Constants.OWN_ORDER_ORDERCOMMENTINFO;
        RequestParams params = new RequestParams(url);
        params.addBodyParameter("session", UserHelper.getInstance().getSessionInfoModel(SeeEvaluateActivity2.this).getSession());
        params.addBodyParameter("storeId", storeId + "");
        params.addBodyParameter("orderNumber", order_number);
        x.http().post(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {

                try {
                    String data = PhoneUtils.checkResponseFlag(SeeEvaluateActivity2.this, result);
                    if (data != null) {
                        SeeEvaluateModel model = GsonUtils.getBean(data, SeeEvaluateModel.class);
                        ratingbarBigEncourage.setRating(model.getSatisfaction());
                        ratingbarIntimateIndex.setRating(model.getSweetIndex());
                        ratingbarBenefitIndex.setRating(model.getEconomicalIndex());
                        ratingbarEfficiencyIndex.setRating(model.getEfficiencyIndex());
                        tvContent.setText(model.getContent());
                    }
                } catch (Exception e) {

                }


            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {

            }

            @Override
            public void onCancelled(CancelledException cex) {

            }

            @Override
            public void onFinished() {
                mLoadView.CancleLoadView();
            }
        });
    }


}
